package cn.batch.sample.csv;

import java.util.HashMap;
import java.util.Map;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameter;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class JobLaunch {
	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext("cn/batch/sample/csv/batch.xml");
        JobLauncher launcher = (JobLauncher) context.getBean("jobLauncher");
        Job job = (Job) context.getBean("csvJob");
        try {
        	
        	Map<String, JobParameter> params = new HashMap<String, JobParameter>();
        	params.put("inputFile", new JobParameter("cn/batch/sample/csv/inputFile.csv"));
        	params.put("outputFile", new JobParameter("cn/batch/sample/csv/outputFile.csv"));
        	
            JobExecution result = launcher.run(job, new JobParameters(params));
            System.out.println(result.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
